package com.koron.system.unityUser.controller;

import com.koron.system.unityUser.entity.*;
import com.koron.system.unityUser.service.UnityUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * description: UnityUserController
 * @author huangsj
 * @date 2023/7/3 9:06
 */

@RestController
@Api(value = "统一用户同步接口")
@RequestMapping("/system/Unity")
public class UnityUserController {
    @Autowired
    private UnityUserService unityUserService;

    @ApiOperation(value = "登录接口")
    @GetMapping("/hello")
    public WsResult<String> hello(String permissionCode, @NonNull String userNameMd5, @NonNull String passwordMd5) {
        WsResult<String> wsResult = unityUserService.hello(permissionCode, userNameMd5, passwordMd5);
        int resultCode = wsResult.getCode() == 1 ? HttpStatus.OK.value() : wsResult.getCode();
        wsResult.setCode(resultCode);
        return wsResult;
    }

    @ApiOperation(value = "标段类型字典")
    @GetMapping("/bidTypeDictionary")
    public WsResultList<UumsBidType> bidTypeDictionary(String auth) {
        return unityUserService.bidTypeDictionary(auth);
    }

    @ApiOperation(value = "机构类型字典")
    @GetMapping("/organizationTypeDictionary")
    public WsResultList<UumsOrganizationType> organizationTypeDictionary(@NonNull String auth) {
        return unityUserService.organizationTypeDictionary(auth);
    }

    @ApiOperation(value = "系统状态字典")
    @GetMapping("/appStateDictionary")
    public WsResultList<UumsAppState> appStateDictionary(@NonNull String auth) {
        return unityUserService.appStateDictionary(auth);
    }

    @ApiOperation(value = "珠三角工程信息")
    @GetMapping("/project")
    public WsResult<UumsProject> project(@NonNull String auth) {
        return unityUserService.project(auth);
    }

    @ApiOperation(value = "组织机构同步")
    @GetMapping("/organizationList")
    public WsResultList<UumsOrganization> organizationList(String auth,String orgCode){
        WsResultList<UumsOrganization> wsResultList = unityUserService.organizationList(auth, orgCode);
        int resultCode = wsResultList.getCode() == 1 ? HttpStatus.OK.value() : wsResultList.getCode();
        wsResultList.setCode(resultCode);
        wsResultList.setData(null); // 数据量太大返回给前端会卡死
        return wsResultList;
    }

    @ApiOperation(value = "公司信息")
    @GetMapping("/companyListcompanyList")
    public WsResultList<UumsCompany> companyListcompanyList(String auth, String companyCode) {
        return unityUserService.companyListcompanyList(auth,companyCode);
    }

    @ApiOperation(value = "标段信息")
    @GetMapping("/bidListbidList")
    public WsResultList<UumsBid> bidListbidList(String auth, String bidCode) {
        return unityUserService.bidListbidList(auth,bidCode);
    }

    @ApiOperation(value = "子系统信息")
    @GetMapping("/appList")
    public WsResultList<UumsApp> appList(String auth, String sysCode) {
        return unityUserService.appList(auth,sysCode);
    }

    @ApiOperation(value = "通过ID查询用户授权信息")
    @GetMapping("/appListByUserId")
    public WsResultList<UumsApp> appListByUserId(String auth, String uumsUserId) {
        return unityUserService.appListByUserId(auth,uumsUserId);
    }

    @ApiOperation(value = "通过ID查询用户信息")
    @GetMapping("/UserById")
    public WsResult<UumsUser> UserById(String auth, String uumsUserId) {
        return unityUserService.UserById(auth,uumsUserId);
    }

    @ApiOperation(value = "通过用户名密码查询用户信息")
    @GetMapping("/UserByLNmPw")
    public WsResultUumsUser UserByLNmPw(String auth, String userNameMd5, String passwordMd5) {
        return unityUserService.UserByLNmPw(auth,userNameMd5,passwordMd5);
    }

    @ApiOperation(value = "通过公司编码、组织机构编码、系统编码查询用户信息")
    @GetMapping("/UserList")
    public WsResultList<UumsUser> UserList(String auth, String companyCode, String organizationCode, String sysCode) {
        WsResultList<UumsUser> wsResultList = unityUserService.UserList(auth, companyCode, organizationCode, sysCode);
        int resultCode = wsResultList.getCode() == 1 ? HttpStatus.OK.value() : wsResultList.getCode();
        wsResultList.setCode(resultCode);
         wsResultList.setData(null); // 数据量太大返回给前端会卡死
        return wsResultList;
    }

    @ApiOperation(value = "修改用户密码")
    @GetMapping("/changePassword")
    public WsResult<Integer> changePassword(String auth, String userId, String oldPasswordMd5, String newPasswordMd5, String confirmPasswordMd5) {
        return unityUserService.changePassword(auth,userId,oldPasswordMd5,newPasswordMd5,confirmPasswordMd5);
    }
}
